import React, { Component, Suspense, lazy, useState } from 'react';
import { Route, Switch, withRouter } from 'react-router-dom';
import MainContext from '../../context/MainContext';
import { JSEncrypt } from 'jsencrypt'
import AjaxUtils from '../../utils/AjaxUtils'
// import Home from'./A';
// import About from './B';

const Home = lazy(() => import('./A'));
const About = lazy(() => import('./B'));

import './App.css';

class App extends Component {

  static contextType = MainContext

  componentDidMount() {
    // this.props.history.push('/about')
    // const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANYwyGngUqCX4AaZriRS4OJYNLnJhexY/tdzjHaCA/VgKPidKwzfwKlbq+WekTRNzLThqsLrZcvuCikai5/dkh0CAwEAAQ==';
    // const encrypt = new JSEncrypt();
    // encrypt.setPublicKey(publicKey);
    // const password = '123456abc'
    // let encode= encrypt.encrypt(password); //password为需要加密的字段
    // console.log(encode);
    // const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA1jDIaeBSoJfgBpmuJFLg4lg0ucmF7Fj+13OMdoID9WAo+J0rDN/AqVur5Z6RNE3MtOGqwutly+4KKRqLn92SHQIDAQABAkB/I0PC/OFu69eRc2VXsE5GbF8XrJQu/4B9eNv2eCRLYCr2GAmyxsb9sww/fdHk573wCxCiAEDVxuE/g/kxAPyBAiEA/WX9JdpGiVpYHa0YxmQMYCpaPZylvovLOk+qjANekD0CIQDYY75QKS2gwaGt9osCHtODKtgTiBi2zQADLwNKw6hHYQIgDAJjZwHbSfMwLefgPrbLJ1uaf0UHTeqOLStNZ+lY9/kCIHlj8xaLEzK0jVvHDBJjcqqJtW+3kI20EQa4L/OYMWXhAiEA9mrH7KKtyzBCr1853qaI/M13sSFOLvHsbIc9VFkxLVE=';
    // encrypt.setPrivateKey(privateKey)
    // let jiemi = encrypt.decrypt(encode);
    // console.log(jiemi)
    AjaxUtils.put("/person").then(res => {
      console.log(res);
    })

  }


  render() {
    const { match, location, history } = this.props;
    return (
      <div>
        <h1>dfsfdsfsdfd</h1>
        <Suspense fallback={<div>Loading...</div>}>
          <Switch >
            <Route exact path="/" component={Home} />
            <Route path="/about" component={About} />
          </Switch>
        </Suspense>
      </div>
    );
  }
}

// function App() {
//   // 声明一个叫 “count” 的 state 变量。
//   const [count, setCount] = useState(0);

//   return (
//     <div>
//       <p>You clicked {count} times</p>
//       <button onClick={() => setCount(count + 1)}>
//         Click me
//       </button>
//     </div>
//   );
// }

export default withRouter(App);
